home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
music4c.sit
/
Music4C Folder
/
Sources Folder
/
MacInterface2.c
< prev
next >
Wrap
Text File
|
1990-09-09
|
10KB
|
391 lines
/*
* ⌐ Graeme Gerrard 1990
* Faculty of Music, University of Melbourne
* Parkville Victoria 3052 Australia.
*
* ARPANET: grae@murdu.ucs.unimelb.edu.au
* telephone: (613) 344 4127, Fax: (613) 344 5346
*/
#include "Music4C.h"
#include "Music4C_Prototype.h"
#include "Synthesis_Time.h"
void prepareSDfile(double);
void prepareAIFFfile(double, int);
Boolean pass3(void);
void FixHeaderInfo(void);
void tell_mem(void);
Boolean Mac_write3(float *, float);
void readBack(void);
DialogPtr thePass3DialogPtr;
extern void D_Synthesis_Progress(void);
static pascal char MyFilter (DialogPtr theDialog, EventRecord *theEvent, short *itemHit);
static void Refresh_Dialog(DialogPtr GetSelection);
void DisplayDialog(DialogPtr);
#define I_Cancel 1
#define I_OK 1
static void Refresh_Dialog(GetSelection)
DialogPtr GetSelection;
{
Rect tempRect;
short DType;
Handle DItem;
GetDItem(GetSelection,I_OK, &DType, &DItem, &tempRect);
PenSize(3, 3);
InsetRect(&tempRect, -4, -4);
FrameRoundRect(&tempRect, 16, 16);
PenSize(1, 1);
}
/* ======================================================== */
static Handle aHand;
extern OSErr theErr;
extern Boolean AIFFoddByte;
extern int nrec;
static Rect prgBox;
extern double TotalDuration;
extern int nchnls;
extern double srate;
static double barStep;
static int NumberOfRecordsToWrite;
static int *theIbuf;
static double theScalefactor;
static DialogPtr GetSelection;
static int type;
Boolean MAC_do_pass3()
{
Rect tempRect;
short itemHit;
long nTicks;
long startTick;
long TotalTicks;
char theChar;
extern CursHandle theCursor;
extern ioParam myIOParmBlk;
extern int SFoutputType;
extern Boolean CreateSoundFile;
extern long TotalSamps;
extern Str255 theMess1;
Boolean result;
GetSelection = GetNewDialog(PASS3_DIALOG, NIL, (WindowPtr)-1);
thePass3DialogPtr = GetSelection;
tempRect.top = GetSelection->portRect.top;
tempRect.left = GetSelection->portRect.left;
tempRect.bottom = GetSelection->portRect.bottom;
tempRect.right = GetSelection->portRect.right;
tempRect.top = -GetSelection->portBits.bounds.top;
tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;
MoveWindow(GetSelection, tempRect.left, tempRect.top, TRUE);
NumberOfRecordsToWrite = (int) (((TotalDuration * nchnls) * (srate / SAMPBUFSZ)) + 0.5);
GetDItem(GetSelection, 2, &type, &aHand, &prgBox);
barStep = (double)(prgBox.right - prgBox.left ) / (double)NumberOfRecordsToWrite;
theCursor = GetCursor(watchCursor);
SetCursor(*theCursor);
/* are we dealing with a SD file ? */
if ( CreateSoundFile ) {
if ( SFoutputType == SD ) {
myIOParmBlk.ioPosMode = fsAtMark;
myIOParmBlk.ioPosOffset = NIL;
myIOParmBlk.ioCompletion = NIL;
if ( nchnls == 1 )
prepareSDfile(TotalDuration);
theScalefactor = SAMPMAX; /* not actually used */
theIbuf = (int *)NewPtr(sizeof(int) * SAMPBUFSZ);
}
else if ( SFoutputType == AIFF ) {
prepareAIFFfile(TotalDuration, nchnls);
theScalefactor = SAMPMAX; /* not actually used */
theIbuf = (int *)NewPtr(sizeof(int) * SAMPBUFSZ);
}
else if ( SFoutputType == INT16 ) {
theIbuf = (int *)NewPtr(sizeof(int) * SAMPBUFSZ);
theScalefactor = 1.0;
myIOParmBlk.ioReqCount = TotalDuration * nchnls * srate * sizeof(int);
myIOParmBlk.ioCompletion = NIL;
if ( (theErr = PBAllocContig(&myIOParmBlk, FALSE)) != noErr ) {
if ( theErr == dskFulErr ) {
if ( (theErr = PBAllocate(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pCan't allocate disk space for sound file");
OSError(theMess1, NIL, NIL);
}
}
}
}
}
startTick = TickCount();
FlushEvents(everyEvent,0);
ShowWindow(GetSelection);
SelectWindow(GetSelection);
SetPort(GetSelection);
DisplayDialog(GetSelection);
result = pass3();
DisposDialog(GetSelection);
/* all finished */
if ( SFoutputType == AIFF ) {
if ( AIFFoddByte ) {
myIOParmBlk.ioReqCount = 1L;
theChar = '\0';
myIOParmBlk.ioBuffer = (Ptr)theChar;
if ( (theErr = PBWrite(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError writing to sample file");
OSError(theMess1, NIL, NIL);
}
}
FixHeaderInfo();
}
TotalTicks = TickCount() - startTick;
NumToString((TotalTicks / 60), theMess1);
InitCursor();
ParamText(theMess1, NIL, NIL, NIL);
D_Synthesis_Time();
if ( result )
return(TRUE);
else
return(FALSE);
}
Boolean Mac_write3(theSamps, synthTime)
float *theSamps;
float synthTime;
{
register i;
extern Boolean CreateSoundFile;
extern int wrote_rec;
extern ioParam myIOParmBlk;
long nBytes;
EventRecord event;
long Number;
long aLong;
char c;
Rect aRect;
int type;
int rightPoint;
int *Iptr;
float *sp;
double x;
long nSamps;
Point where, P1, P2, P3;
Rect tempRect;
short DType;
short itemHit;
Handle DItem;
extern float MaxSample;
extern float MinSample;
long fTicks;
nrec++;
nBytes = (long)SAMPBUFSZ * sizeof(float);
if (CreateSoundFile) {
myIOParmBlk.ioCompletion = NIL;
switch(SFoutputType ) {
case FLOAT:
myIOParmBlk.ioReqCount = nBytes;
myIOParmBlk.ioBuffer = (Ptr)theSamps;
if ( (theErr = PBWrite(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError writing to sample file");
OSError(theMess1, NIL, NIL);
}
if ( myIOParmBlk.ioActCount != nBytes ) {
PstringCopy((char *)theMess1, "\pError writing to sample file wrote wrong number of bytes");
OSError(theMess1, NIL, NIL);
}
break;
case SD:
case SD2:
nSamps = SAMPBUFSZ;
nBytes = (long)SAMPBUFSZ * sizeof(int);
for ( i = 0, Iptr = theIbuf, sp = theSamps; i < nSamps; i++ ) {
x = *sp++;
if ( x < MinSample )
MinSample = x;
if ( x > MaxSample )
MaxSample = x;
*Iptr++ = (int)x;
}
/* write it out */
myIOParmBlk.ioReqCount = (long)(nSamps * sizeof(int));
myIOParmBlk.ioBuffer = (Ptr)theIbuf;
if ( (theErr = PBWrite(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError writing to sample file");
OSError(theMess1, NIL, NIL);
}
if ( myIOParmBlk.ioActCount != myIOParmBlk.ioReqCount ) {
PstringCopy((char *)theMess1, "\pError writing to sample file wrote wrong number of bytes");
OSError(theMess1, NIL, NIL);
}
break;
case AIFF:
nSamps = SAMPBUFSZ;
TotalSamps += nSamps;
nBytes = (long)SAMPBUFSZ * sizeof(int);
for ( i = 0, Iptr = theIbuf, sp = theSamps; i < nSamps; i++ ) {
x = *sp++;
if ( x < MinSample )
MinSample = x;
if ( x > MaxSample )
MaxSample = x;
*Iptr++ = (int)x;
}
/* write it out */
myIOParmBlk.ioReqCount = (long)(nSamps * sizeof(int));
myIOParmBlk.ioBuffer = (Ptr)theIbuf;
if ( (theErr = PBWrite(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError writing to sample file");
OSError(theMess1, NIL, NIL);
}
if ( myIOParmBlk.ioActCount != myIOParmBlk.ioReqCount ) {
PstringCopy((char *)theMess1, "\pError writing to sample file wrote wrong number of bytes");
OSError(theMess1, NIL, NIL);
}
break;
case INT16:
nSamps = SAMPBUFSZ;
nBytes = (long)SAMPBUFSZ * sizeof(int);
for ( i = 0, Iptr = theIbuf, sp = theSamps; i < nSamps; i++ ) {
x = *sp++;
if ( x < MinSample )
MinSample = x;
if ( x > MaxSample )
MaxSample = x;
*Iptr++ = (int)x;
}
/* write it out */
myIOParmBlk.ioReqCount = (long)(nSamps * sizeof(int));
myIOParmBlk.ioBuffer = (Ptr)theIbuf;
if ( (theErr = PBWrite(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError writing to sample file");
OSError(theMess1, NIL, NIL);
}
if ( myIOParmBlk.ioActCount != myIOParmBlk.ioReqCount ) {
PstringCopy((char *)theMess1, "\pError writing to sample file wrote wrong number of bytes");
OSError(theMess1, NIL, NIL);
}
break;
}
}
SetPort(GetSelection);
rightPoint = prgBox.left + (nrec * barStep);
if ( rightPoint > prgBox.right )
rightPoint = prgBox.right;
if ( nrec == NumberOfRecordsToWrite )
rightPoint = prgBox.right;
SetRect(&aRect, prgBox.left, prgBox.top, rightPoint, prgBox.bottom);
FillRect(&aRect, gray);
/* Refresh_Dialog(GetSelection); */
wrote_rec = 1;
GetNextEvent(everyEvent, &event);
if ( IsDialogEvent(&event) ) {
if ( DialogSelect(&event, &GetSelection, &itemHit)) {
if ( itemHit == 1) {
SetRect(&tempRect, 185, 72, 265, 92 );
InsetRect(&tempRect, 1, 1 );
InvertRoundRect(&tempRect, 8, 8 );
Delay(30L, &fTicks);
return(FALSE);
}
}
}
return(TRUE);
}
void tell_mem()
{
long freemem1;
long stackspace1;
Size maxmem1;
long maxblock1;
long aLong1, anotherLong1;
Size aSize1;
THz syszone1;
Size totalmem1;
long freemem2;
long stackspace2;
Size maxmem2;
long maxblock2;
long aLong2, anotherLong2;
Size aSize2;
THz syszone2;
Size totalmem2;
freemem1 = FreeMem();
maxblock1 = MaxBlock();
maxmem1 = (long)MaxMem(&aSize1);
stackspace1 = StackSpace();
syszone1 = SystemZone();
anotherLong1 = (long)syszone1;
totalmem1 = (long)CompactMem(maxSize);
freemem2 = FreeMem();
maxblock2 = MaxBlock();
maxmem2 = (long)MaxMem(&aSize2);
stackspace2 = StackSpace();
syszone2 = SystemZone();
anotherLong2 = (long)syszone2;
totalmem2 = (long)CompactMem(maxSize);
}
void readBack()
{
extern float *SampsPtr;
long nBytes;
/* this code reads it back for checking */
myIOParmBlk.ioPosMode = fsFromMark;
myIOParmBlk.ioPosMode = fsFromStart;
myIOParmBlk.ioPosOffset = NIL;
theErr = PBSetFPos(&myIOParmBlk, FALSE);
myIOParmBlk.ioPosMode = fsAtMark;
myIOParmBlk.ioReqCount = nBytes;
myIOParmBlk.ioPosMode = fsAtMark;
myIOParmBlk.ioPosOffset = NIL;
myIOParmBlk.ioBuffer = (Ptr)SampsPtr;
if ( (theErr = PBRead(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError reading back sample file");
OSError(theMess1, NIL, NIL);
}
if ( myIOParmBlk.ioActCount != nBytes ) {
PstringCopy((char *)theMess1, "\pError reading back sample file wrote wrong number of bytes");
OSError(theMess1, NIL, NIL);
}
}
void DisplayDialog(GetSelection)
DialogPtr GetSelection;
{
DrawDialog(GetSelection);
GetDItem(GetSelection, 2, &type, &aHand, &prgBox);
FrameRect(&prgBox);
}